Fix transitively updating dependencies
authorAlex Crichton <alex@alexcrichton.com>
Thu, 30 Apr 2015 01:42:52 +0000 (18:42 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Thu, 30 Apr 2015 01:45:47 +0000 (18:45 -0700)
Currently when a dependency is transitively updated the source may not itself be
updated, so an update may not happen at all. This commit modifies this behavior
to be sure to add the non-updated source to the registry for any matching
package which will trigger the source to update itself.

src/cargo/ops/cargo_generate_lockfile.rs
tests/test_cargo_registry.rs

index a314003b81575d6b5c200cf9296d419489fb088e..2c97a3dd36b5a8c07cba2f97d8827a9938774125 100644 (file)
@@ -73,7 +73,11 @@ pub fn update_lockfile(manifest_path: &Path,
                                          .with_precise(Some(precise));
                         try!(registry.add_sources(&[precise]));
                     }
-                    None => {}
+                    None => {
+                        let imprecise = dep.source_id().clone()
+                                           .with_precise(None);
+                        try!(registry.add_sources(&[imprecise]));
+                    }
                 }
             }
         }
index 3f7a70ebfb521c3a4ee56648ec531ac2cc7ba630..4dc750a99810dac8db2f9eac3e53e3a6973f9271 100644 (file)
@@ -733,3 +733,41 @@ test!(fetch_downloads {
 {downloading} a v0.1.0 (registry [..])
 ", updating = UPDATING, downloading = DOWNLOADING)));
 });
+
+test!(update_transitive_dependency {
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [project]
+            name = "foo"
+            version = "0.5.0"
+            authors = []
+
+            [dependencies]
+            a = "0.1.0"
+        "#)
+        .file("src/main.rs", "fn main() {}");
+    p.build();
+
+    r::mock_pkg("a", "0.1.0", &[("b", "*", "normal")]);
+    r::mock_pkg("b", "0.1.0", &[]);
+
+    assert_that(p.cargo("fetch"),
+                execs().with_status(0));
+
+    r::mock_pkg("b", "0.1.1", &[]);
+
+    assert_that(p.cargo("update").arg("-pb"),
+                execs().with_status(0)
+                       .with_stdout(format!("\
+{updating} registry `[..]`
+", updating = UPDATING)));
+
+    assert_that(p.cargo("build"),
+                execs().with_status(0)
+                       .with_stdout(format!("\
+{downloading} b v0.1.1 (registry file://[..])
+{compiling} b v0.1.1 (registry [..])
+{compiling} a v0.1.0 (registry [..])
+{compiling} foo v0.5.0 ([..])
+", downloading = DOWNLOADING, compiling = COMPILING)));
+});